#include <bits/stdc++.h>
#define ll long long
#define poly vector<ll>
using namespace std;

const int Maxn=1e6+5,N=1e6;
int n,p;
ll fac[Maxn],Inv[Maxn],ans,f[Maxn];

inline ll ksm(ll a,int b,int mod){
    ll z=1;
    while(b){
        if(b&1) z=z*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return z;
}
inline ll Anm(int x,int y){
    if(y>x or y<0) return 0;
    return fac[x]*Inv[x-y]%p;
}
inline ll Binom(int x,int y){
    if(y==1) return 1;
    if(y>x or y<0) return 0;
    return fac[x]*Inv[y]%p*Inv[x-y]%p;
}
inline ll Get(int x){
    if(x==1) return 1;
    return ksm(x,x-2,p)*ksm(2,x-1,p)%p;
}

int main(){
    freopen("tree.in","r",stdin);
    freopen("tree.out","w",stdout);
    scanf("%d%d",&n,&p);
    const int P=p;
    fac[0]=1;
    for(int i=1;i<=N;i++) fac[i]=fac[i-1]*i%P;
    Inv[N]=ksm(fac[N],P-2,P);
    for(int i=N-1;~i;i--) Inv[i]=Inv[i+1]*(i+1)%P;

    for(int i=1;i<=n;i++){
        f[0]=1;
        for(int j=1;j<=n;j++) f[j]=0;
        for(int j=1;j<=n;j++)
            for(int k=j;k<=n;k++)
                f[k]=(f[k]+f[k-j]*2%P*Get(j)%P*j%P*i%P)%P;
        // cout<<"hel "<<i<<" "<<f[n-i]<<endl;
        ans=(ans+f[n-i]*Anm(n,i)%P)%P;
    }

    printf("%lld",ans);

    system("pause");
    return 0;
}
/*
10 998244853

4 998244353

3 2007329

2 2007329

1 2007329
*/